package com.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hqj.ReturnUtil;
import com.springboot.domain.Menu;
import com.springboot.domain.MenuOV;
import com.springboot.service.MenuServiceI;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/mc")
public class MenuController extends BaseController<Menu> {

    @Resource(name = "menuServiceI")
    private MenuServiceI msi;

    @Override
    public List<Menu> find(Menu menu) {
        //条件构造器
        QueryWrapper<Menu> qw = new QueryWrapper<>();
        if(menu.getId()!=null){
            qw.eq("id",menu.getId());
        }
        if(menu.getMenuName()!=null){
            qw.like("menu_name",menu.getMenuName());
        }
        qw.orderByDesc("create_time","id");
        return msi.list(qw);
    }

    /**
     * 分页查询
     * @param menu
     * @return
     */
    @RequestMapping("/pageFind")
    @ResponseBody
    public MenuOV pageFind(Menu menu) {
        return msi.pageList(menu,2,10);
    }

    @Override
    public Map<String, Object> add(Menu menu) {

        boolean b = msi.save(menu);

        return ReturnUtil.returnMap(b,"新增");
    }

    @Override
    public Map<String, Object> edit(Menu menu) {
        boolean b = msi.updateById(menu);
        return ReturnUtil.returnMap(b,"编辑");
    }

    @Override
    public Map<String, Object> remove(Menu menu) {
        boolean b = msi.removeById(menu.getId());
        return ReturnUtil.returnMap(b,"删除");
    }
}
